/**
 * 资源树表格
 */
Ext.define('BenBen.modules.system.resource.ResourceTreeGrid', {
    extend: 'BenBen.common.BaseTreeGrid',
    isDistribute : false, //是否为分配使用
    initComponent: function () {
    	var me = this;
    	
    	Ext.define('Resource', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id',     type: 'string'},
                {name: 'name',     type: 'string'},
                {name: 'iconCls',     type: 'string'},
                {name: 'resourceIcon',     type: 'string'},
                {name: 'url', type: 'string'},
                {name: 'state', type: 'string'},
                {name: 'checked',     type: 'boolean'}
            ]
        });

    	var url = 'system/resource';
    	if(me.roleId){
    		url += '?roleId='+ me.roleId;
    	}
    	var store = Ext.create('Ext.data.TreeStore', {
            model: 'Resource',
            proxy: {
                type: 'ajax',
                url: url
            }
        });
        
        var form = Ext.create('BenBen.modules.system.resource.ResourceForm',{
    		parentStore : store
    	});
        
        
        var columns = null;
        if(me.isDistribute){
        	columns = [{
                xtype: 'treecolumn',
                text: '资源名称',
                flex: 2,
                dataIndex: 'name'
            },{
            	header: '状态',
            	flex: 1,
            	dataIndex: 'state',
                renderer: function (value) {
                    if (value == 1) {
                        return "模块";
                    }else if (value == 2) {
                        return "按钮";
                    }else if (value == 3) {
                    	return "其它";
                    } 
                }
            }];
        }else{
        	columns = [{
                xtype: 'treecolumn',
                text: '资源名称',
                flex: 2,
                dataIndex: 'name'
            },{
            	header: '图标',
                flex: 1,
                dataIndex: 'resourceIcon'
            },{
            	header: '路径',
                flex: 1,
                dataIndex: 'url'
            },{
            	header: '状态',
            	flex: 1,
            	dataIndex: 'state',
                renderer: function (value) {
                    if (value == 1) {
                        return "模块";
                    }else if (value == 2) {
                        return "按钮";
                    }else if (value == 3) {
                    	return "其它";
                    } 
                }
            }];
        }

        Ext.apply(this,{
            border : false,
            store: store,
            dataForm : form,
            config : {
				winWidth : 400,
                winHeigth : 210,
				pageSize : 30,
				url : 'system/resource'
			},
            columns: columns
        });
        this.callParent(arguments);
    }
});
